package com.fh.controller;

import com.fh.common.ResultEnum;
import com.fh.common.ResultMessage;
import com.fh.model.dto.OrderInfoDTO;
import com.fh.service.OrderService;
import com.fh.vo.OrderInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @RequestMapping("addOrder")
    public ResultMessage addOrder(OrderInfoVo orderInfoVo){
        try {
            orderService.addOrder(orderInfoVo);
            return new ResultMessage(ResultEnum.INSERT_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultMessage(ResultEnum.INSERT_ERROR);
        }

    }
    @RequestMapping("queryOrderList")
    public ResultMessage queryOrderList(Long userId){
        try {
            List<OrderInfoDTO> orderList=orderService.queryOrderList(userId);
            return new ResultMessage(ResultEnum.QUERY_SUCCESS,orderList);
        }catch (Exception e) {
            e.printStackTrace();
            return new ResultMessage(ResultEnum.QUERY_ERROR);
        }
    }
}
